/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package components.shape;

import Enums.ProjectType;
import PCR.MainFrame;
import components.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 *
 * @author icdev
 */
public class ShapeMouseAction implements MouseListener {

    MainFrame frm = (MainFrame) java.awt.Window.getWindows()[0];

    @Override
    public void mouseClicked(MouseEvent e) {

        Shape curBand = (Shape) e.getSource();
        frm.getSelectedWorkArea().getBandsPanel().getShapeMenu().setCurrentBand(curBand);
        curBand.grabFocus();
        frm.setSelectedShape(curBand);
        frm.getSampleCombo().setSelectedItem(curBand.getCurSample());
        Integer pos = frm.getSelectedWorkArea().getBandsPanel().getHeight() - curBand.getBounds().y;
        if (frm.getSampleCombo().getItemCount() == 16) {
            int i = 1;
            while (i < frm.getSelectedWorkArea().get16Position().length) {
                if (frm.getSelectedWorkArea().get16Position()[i] == curBand.getBounds().x) {
                    break;
                } else {
                    i++;
                }
            }
            frm.getSampleCombo().setSelectedItem(i);
        } else if (frm.getSampleCombo().getItemCount() == 4) {
            int i = 1;
            while (i < frm.getSelectedWorkArea().get4Position().length) {
                if (frm.getSelectedWorkArea().get4Position()[i] == curBand.getBounds().x) {
                    break;
                } else {
                    i++;
                }
            }
            frm.getSampleCombo().setSelectedItem(i);
        } else {
            int i = 1;
            while (i < frm.getSelectedWorkArea().get8Position().length) {
                if (frm.getSelectedWorkArea().get8Position()[i] == curBand.getBounds().x) {
                    break;
                } else {
                    i++;
                }
            }
            frm.getSampleCombo().setSelectedItem(i);
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {
        Shape curBand = (Shape) e.getSource();
        if (e.isPopupTrigger()) {
            if(curBand instanceof Band)
            {
                frm.getSelectedWorkArea().getBandsPanel().getShapeMenu().setBrightnessItemAvilabelity(true);
            }
            else
            {
                 frm.getSelectedWorkArea().getBandsPanel().getShapeMenu().setBrightnessItemAvilabelity(false);
            }
            frm.setSelectedShape(curBand);
            curBand.grabFocus();
            frm.getSampleCombo().setSelectedItem(curBand.getCurSample());
        }
        frm.getSelectedWorkArea().getBandsPanel().getShapeMasure().setLocation(0, curBand.getLocation().y + curBand.getSize().height / 2);
        frm.getSelectedWorkArea().getBandsPanel().getShapeMasure().setWidth(curBand.getLocation().x);
        frm.getSelectedWorkArea().getBandsPanel().getShapeMasure().setVisible(true);
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        Shape curBand = (Shape) e.getSource();
        frm.getSelectedWorkArea().getBandsPanel().getShapeMenu().setCurrentBand(curBand);
        frm.getSelectedWorkArea().getBandsPanel().getTipText().setVisible(false);
        frm.getSelectedWorkArea().getBandsPanel().getShapeMasure().setVisible(false);
        frm.setSelectedShape(curBand);
        curBand.grabFocus();
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }
}
